package com.panshi.controller;

import com.alibaba.fastjson.util.TypeUtils;
import com.fasterxml.jackson.databind.MapperFeature;
import com.panshi.service.ZxService;
import com.panshi.vo.ArticleT;
import com.panshi.vo.WebResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin
//@RequestMapping(produces = {"application/json;charset=UTF-8"})
public class ZController {

    @Autowired
    private ZxService zxService;

    @GetMapping("/zx-app/list")
    @ResponseBody
    public WebResult findArticle(int page, int limit) {
        WebResult webResult = new WebResult();
        webResult.setCode(0);
        webResult.setData(zxService.findArticle(page));
        return webResult;
    }

    /*
        @GetMapping("/zx-app/byid/{id}")
        public ArticleT getZxbyId(@PathVariable("id") Integer id){
            ArticleT article = zxService.getById(id);
            return zxService.getById(id);
        }

        @PostMapping("/zx-app/add")
        public Boolean add(@Validated ArticleT articleT){
            return zxService.save(articleT);
        }

        @GetMapping("/zx-app/del/{id}")
        public Boolean del(@PathVariable("id") Integer id){
            ArticleT articleT = new ArticleT();
            articleT.setId(id);
            articleT.setAState(-1);
            return zxService.updateById(articleT);
        }

        */
    @PostMapping("/zx-app/add")
    @ResponseBody
    public Boolean add(@Validated ArticleT articleT) {
        System.out.println(articleT);
        return zxService.insertArticleT(articleT);
    }

    @PostMapping("/zx-app/upd")
    @ResponseBody
    public Boolean upd(@Validated ArticleT articleT) {
        System.out.println(articleT);
        return zxService.updateArticleT(articleT);
    }

    @PostMapping("/zx-app/pass")
    @ResponseBody
    public Boolean pass(@Validated ArticleT articleT) {
        System.out.println(articleT);
        return zxService.insertArticle(articleT);
    }

}
